package com.meida.student.app.user.handler;

import com.meida.common.base.entity.EntityMap;
import com.meida.common.base.utils.FlymeUtils;
import com.meida.common.mybatis.interceptor.PageInterceptor;
import com.meida.common.mybatis.model.PageParams;
import com.meida.common.mybatis.query.CriteriaQuery;
import com.meida.module.bus.client.entity.BusSubject;
import org.springframework.stereotype.Component;

/**
 * 题目分类接口逻辑
 * @author zyf
 */
@Component
public class SubjectListHandler implements PageInterceptor<BusSubject> {

    @Override
    public void prepare(CriteriaQuery<BusSubject> cq, PageParams pageParams, EntityMap params) {
        cq.clear();
        Long parentId = params.getLong("parentId");
        cq.select(BusSubject.class, "subjectId", "subjectTitle","amount");
        //查询已审核的
        cq.eq(BusSubject.class, "state", 2);
        if (FlymeUtils.isEmpty(parentId)) {
            cq.eq(BusSubject.class, "parentId", 0);
        } else {
            //查询子分类
            cq.eq(BusSubject.class, "parentId", parentId);
        }
        cq.like(BusSubject.class, "subjectTitle");
    }
}
